<?php

namespace app\queue\redis;

use app\common\lib\RedisQueue;
use app\common\lib\TencentCos;
use Webman\RedisQueue\Consumer;

class UploadVideo implements Consumer
{
    // 要消费的队列名
    public $queue = 'asyncUploadVideo';

    // 连接名，对应 plugin/webman/redis-queue/redis.php 里的连接`
    public $connection = 'default';

    // 消费
    public function consume($data)
    {
        try{
            sleep(3);
            var_dump('asyncUploadVideo---'.mt_rand(1000,9999));
            RedisQueue::getInstance()->saveQueue($this->queue,$data,[]);
        }catch (\Exception $e){
            RedisQueue::getInstance()->saveQueue($this->queue,$data,['error'=>$e->getMessage()]);
        }

        // 无需反序列化
//        var_export($data);
//        var_export('redis_queue_asyncUploadVideo');
//        TencentCos::getInstance()->asyncUploadFile($data['filepath'],$data['uploadid'],'video');
//        @unlink($data['filepath']);
    }
            
}
